package com.hepinghospital.user.ui.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.hepinghospital.user.R;
import com.hepinghospital.user.base.BaseApplication;
import com.hepinghospital.user.base.BaseFragment;
import com.hepinghospital.user.ui.activity.userinfo.MyAskActivity;
import com.rest.business.RestProxy;
import com.rest.observer.BaseObserver;
import com.rest.response.OrderNumbersResponse;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/5/28.
 */

public class MineTuWenFragment extends BaseFragment {


    @BindView(R.id.tv_unreadCount_dzf)
    TextView tvUnreadCountDzf;
    @BindView(R.id.tv_unreadCount_jxz)
    TextView tvUnreadCountJxz;
    @BindView(R.id.tv_unreadCount_dpj)
    TextView tvUnreadCountDpj;
    @BindView(R.id.tv_unreadCount_yqx)
    TextView tvUnreadCountYqx;
    @SuppressLint("StaticFieldLeak")
    private static MineTuWenFragment imFragment;

    public static MineTuWenFragment newInstance() {
        if (imFragment == null) {
            imFragment = new MineTuWenFragment();
            return imFragment;
        } else {
            return imFragment;
        }
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_mine_tuwen;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
    }

    @Override
    public void onResume() {
        super.onResume();
        getOrderNumbers();
    }

    @OnClick(R.id.btn_daizhifu)
    void btn_daizhifu() {
        Bundle bundle = new Bundle();
        bundle.putInt("page", 1);
        startActivity(MyAskActivity.class, bundle);
    }

    @OnClick(R.id.btn_weikaishi)
    void btn_weikaishi() {
        Bundle bundle = new Bundle();
        bundle.putInt("page", 2);
        startActivity(MyAskActivity.class, bundle);
    }

    @OnClick(R.id.btn_jinxingzhong)
    void btn_jinxingzhong() {
        Bundle bundle = new Bundle();
        bundle.putInt("page", 3);
        startActivity(MyAskActivity.class, bundle);
    }

    @OnClick(R.id.btn_daipingjia)
    void btn_daipingjia() {
        Bundle bundle = new Bundle();
        bundle.putInt("page", 4);
        startActivity(MyAskActivity.class, bundle);
    }


    private void getOrderNumbers() {
        RestProxy.getInstance().getOrderNumbers(BaseApplication.currentUserId, new BaseObserver<List<OrderNumbersResponse>>() {
            @Override
            public void onSuccess(List<OrderNumbersResponse> orderNumbersResponse) {
                for (int i = 0; i < orderNumbersResponse.size(); i++) {
                    if (orderNumbersResponse.get(i).orderType == 1) {
                        for (int j = 0; j < orderNumbersResponse.get(i).orderNumbsers.size(); j++) {
                            if (orderNumbersResponse.get(i).orderNumbsers.get(j).orderStatus == 1)
                                setNum(tvUnreadCountDzf, orderNumbersResponse.get(i).orderNumbsers.get(j).number);
                            if (orderNumbersResponse.get(i).orderNumbsers.get(j).orderStatus == 3)
                                setNum(tvUnreadCountJxz, orderNumbersResponse.get(i).orderNumbsers.get(j).number);
                            if (orderNumbersResponse.get(i).orderNumbsers.get(j).orderStatus == 4)
                                setNum(tvUnreadCountDpj, orderNumbersResponse.get(i).orderNumbsers.get(j).number);
//                            if (orderNumbersResponse.data.get(i).orderNumbsers.get(j).orderStatus == 5)
//                                setNum(tvUnreadCountYqx, orderNumbersResponse.data.get(i).orderNumbsers.get(j).number);
                        }
                    }
                }
            }
        });
    }


    private void setNum(TextView tv, int num) {
        if (num == 0) {
            tv.setVisibility(View.INVISIBLE);
        } else {
            tv.setVisibility(View.VISIBLE);
            tv.setText(num + "");
        }
    }
}
